// pages/news/news.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listData: [],
    time: '',
    title: '',
    subtitle: '',
    errormsg: '',
  },
  toweb: function (src) {
    wx.setStorageSync('src', src.currentTarget.dataset.src);
    wx.navigateTo({
      url: '../webview/webview',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.showLoading({
      title: '正在加载',
    })
    const link = options.type;
    wx.request({
      url: "https://api.vvhan.com/api/hotlist?type=" + link,
      dataType: 'json',
      success: (res) => {
        const code = res.data.success;
        if (code) {
          this.setData({
            listData: res.data.data,
            time: res.data.update_time,
            title: res.data.title,
            subtitle: res.data.subtitle,
          });
        } else {
          this.setData({
            errormsg: res.data.message
          })
          wx.showToast({
            title: res.data.message,
            icon: 'error'
          })
        }
        wx.hideLoading();
      }
    })
  },

})